/**
 * 系报表配置JS-reportserver.jsp
 */

//项目路径
var strPath = window.document.location.pathname;
//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
var postPath = "/gdp";
var editReportStart = 1;// 1添加、2修改报表配置
var editTemplateStart = 1;// 1添加、2修改模板上传
var dataSource = 0;//数据源个数

var reportServer = reportServer || {};

$(function(){
		reportServer.system.init();//页面默认初始化方法数据
		reportServer.system.clearSession();//清空session缓存
		reportServer.reportConfig.init();//初始化服务配置
});


//页面初始化
reportServer.system={
		init:function() {
			var servertype = reportServer.system.getQueryParmeter("servertype");
			var operate = reportServer.system.getQueryParmeter("operate");
			var servercode = reportServer.system.getQueryParmeter("servercode");
			var projectid = reportServer.system.getQueryParmeter("projectid");
			$("#hid_servertype").val(servertype);//服务类型 添加使用
			$("#hid_operate").val(operate); //操作类型
			$("#hid_serviceId").val(servercode);//服务ID  修改使用
			$("#hid_projectid").val(projectid);//工程ID 添加修改预留
			if(operate == "add") {
				editReportStart = 1;
				$("#serverid").removeAttr("disabled");
			}else if(operate == "edit") {
				editReportStart=2;
				reportServer.reportConfig.getReportServer();//回显报表服务
			}
			reportServer.system.backServicePage();//返回服务页面
			reportServer.system.bootstrapStepInit();//初始化步骤控件
			reportServer.system.fileinputInit();//初始化绑定上传控件
		},
		//返回列表
		backServicePage:function() {
			$("#btn_back").click(function(){
				window.location.href=postPath + "/prjService/index";
				reportServer.system.clearSession();//清空session缓存
			});
		},
		getQueryParmeter:function(name){
			var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);
		    if(r!=null)return  unescape(r[2]); return null;
		},
		bootstrapStepInit: function (){
			$('#rootwizard').bootstrapWizard({
				tabClass: 'bwizard-steps',
				onTabClick: function(tab, navigation, index) {
					if($("#hid_operate").val()=="add") {
						return false
					}else if($("#hid_operate").val()=="edit") {
						return true
					}
				},
				onTabShow: function(tab, navigation, index) {
					if(index == 0){
						$('#next').show(); 
	  					$('#save_btn').hide();
					}else if(index == 1) {
						$('#next').show(); 
	  					$('#save_btn').hide();
	  					reportServer.dateSourcePropertyConfig.dateSourceConfigInit();//初始化获取数据源个数并展示
						reportServer.dateSourcePropertyConfig.dataSourceFileInputInit();//初始化数据源上传控件
						reportServer.reportConfig.saveReportServerConfig();//保存报表服务基本信息到session
						reportServer.reportConfig.saveServerIdToSession();
						reportServer.dateSourcePropertyConfig.dateSourceConfigInit();//初始化获取数据源个数并展示
						reportServer.dateSourcePropertyConfig.dataSourceFileInputInit();//初始化数据源上传控件
						if($("#hid_operate").val() == "edit") {
							$.ajax({
								type : 'get',
								url : postPath + '/system/reportconfig/getReportDataSourceByServer',
								async : false,
								data : {
									'serviceId': $("#serverid").val(),
//									'operate' : $("#hid_operate").val(),
								},
								success: function(result) {
									var count = 1;
									var data = result.data;
									for (var i = 0; i < data.length; i++) {
										if(data[i].repdatasource == "DefaultDataSource"){
											$("#defaultDateSource_span").html(data[i].datasourceurl);
											break;
										}else{
											$("#dateSource_span_"+data[i].repdatasource).html(data[i].datasourceurl);
											count++;
										}
										
									}
								},
								error: function(error) {
									
								}
							});
						}
					}else if(index == 2) {
						reportServer.reportConfig.saveReportServerConfig();//保存报表服务基本信息到session
						reportServer.dataServerParmeterConfig.parmeterConfigInit();//初始化报表参数配置
	  					//reportServer.dataServerParmeterConfig.dbParmeterConfigInit();//初始化数据源服务参数
	  					reportServer.dataServerParmeterConfig.dbParmeterShowTableConfig();
	  					$("#valide_reportMessage").html("");
	  					$('#next').hide(); 
	  					$('#save_btn').show();
					}
				},
				onNext: function(tab, navigation, index) {
		  			if(index == 1) {
		  				var validataResult = reportServer.reportConfig.validationReportConfig();
		  			    var valJrxmlFile = reportServer.reportConfig.valdationJrxmlJasper();
		  				if(!valJrxmlFile){
		  					$("#valide_reportMessage").html("请上传报表模板文件!");
		  					return false;
		  				}else if (!validataResult) {
		  					return false;
						}else{
							reportServer.reportConfig.saveReportServerConfig();//保存报表服务基本信息到session
							reportServer.reportConfig.saveServerIdToSession();
							reportServer.dateSourcePropertyConfig.dateSourceConfigInit();//初始化获取数据源个数并展示
							reportServer.dateSourcePropertyConfig.dataSourceFileInputInit();//初始化数据源上传控件
							if($("#hid_operate").val() == "edit") {
								$.ajax({
									type : 'get',
									url : postPath + '/system/reportconfig/getReportDataSourceByServer',
									async : false,
									data : {
										'serviceId': $("#serverid").val(),
//										'operate' : $("#hid_operate").val(),
									},
									success: function(result) {
										var count = 1;
										var data = result.data;
										for (var i = 0; i < data.length; i++) {
											if(data[i].repdatasource == "DefaultDataSource"){
												$("#defaultDateSource_span").html(data[i].datasourceurl);
												break;
											}else{
												$("#dateSource_span_"+data[i].repdatasource).html(data[i].datasourceurl);
												count++;
											}
											
										}
									},
									error: function(error) {
										
									}
								});
							}
						}
		  			}else if(index == 2) {
		  				var val = reportServer.dateSourcePropertyConfig.valDateSourceExist();
		  				if(!val){
		  					$("#valide_reportMessage").html("请上传数据服务文件!");
		  					return false;
		  				}else{
		  					reportServer.dataServerParmeterConfig.parmeterConfigInit();//初始化报表参数配置
		  					//reportServer.dataServerParmeterConfig.dbParmeterConfigInit();//初始化数据源服务参数
		  					reportServer.dataServerParmeterConfig.dbParmeterShowTableConfig();
		  					$("#valide_reportMessage").html("");
		  					$('#next').hide(); 
		  					$('#save_btn').show(); 
		  				}
		  				
		  			}
					return true;
		  		},
				onPrevious: function(tab, navigation, index) {
					$("#valide_reportMessage").html("");
					if(index == 1) {
						$('#next').show(); 
	  					$('#save_btn').hide(); 
					}
		  			/*var $valid = $("#commentForm").valid();
		  			if(!$valid) {
		  				$validator.focusInvalid();
		  				return false;
		  			}*/
					return true;
		  		}
			});
		},
		fileinputInit: function() {
			$('#templatefile').fileinput({
		        language: 'zh', //设置语言
		        uploadUrl: postPath + 'system/reportconfig/uploadReportTemplate', //上传的地址
	            maxFileCount : 1,
	            browseClass : "btn btn-info", //按钮样式 
		        uploadAsync: false, //默认异步上传
		        showUpload: true, //是否显示上传按钮
		        showRemove : true, //显示移除按钮
		        showPreview : false, //是否显示预览
		        allowedFileExtensions: ['jasper'],

		    }).on("filebatchuploadsuccess", function (event, data, previewId, index) {    //一个文件上传成功
		        //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
		    	if(data.response){
		    		bootbox.alert('文件上传成功！');
		    		$("#templateurl_span").html(data.files[0].name);
		    	}
		    });
			$('#jrxmlfile').fileinput({
		        language: 'zh', //设置语言
		        uploadUrl: postPath + 'system/reportconfig/uploadReporrtJrxml', //上传的地址
	            maxFileCount : 1,
	            browseClass : "btn btn-info", //按钮样式 
		        uploadAsync: true, //默认异步上传
		        showUpload: true, //是否显示上传按钮
		        showRemove : true, //显示移除按钮
		        showPreview : false, //是否显示预览
		        allowedFileExtensions: ['jrxml'],

		    }).on("filebatchuploadsuccess", function (event, data, previewId, index) {    //一个文件上传成功
		        //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
		    	if(data.response){
		    		bootbox.alert('文件上传成功！');
		    		$("#jrxmlurl_span").html(data.files[0].name);
		    	}
		    })
		},
		saveReportConfigInfo: function() {
			var operate = $("#hid_operate").val();
			var ret = false;
			$.ajax({
				type : 'get',
				url : postPath + '/system/reportconfig/saveReportConfig',
				async : false,
				data : {
					'operate' : operate,
				},
				success: function(result) {
					if(result.success) {
						bootbox.alert('报表服务配置保存成功！',function(){
							window.location.reload();
							$("#hid_operate").val("edit");
						});
						ret = true;
					}
				},
				error: function(error) {
					
				}
			});
//			if(ret){
//				
//			}
			
		},
		clearSession: function() {
			$.ajax({
				type : 'get',
				url : postPath + '/system/reportconfig/clearSession',
				async : false,
				data : '',
				success: function(result) {
					
				}
			});
		}
};
//报表服务配置
reportServer.reportConfig={
		init:function(){
			reportServer.reportConfig.reportConfigClick();//初始化报表服务配置选项卡
			reportServer.reportConfig.saveReportServerConfig();//保存报表服务配置按钮
		},
		//初始化报表服务配置选项卡
		reportConfigClick:function() {
			if(editReportStart == 1) {
				editReportStart = 1;
				$("#serverid").removeAttr("disabled");
			}else if(editReportStart == 2) {
				reportServer.reportConfig.getReportServer();//回显报表服务
			}
			
		},
		getReportServer:function() {
			$.ajax({
				type : 'get',
				url : postPath + '/system/reportconfig/getReportConfigInformationByGuid',
				async : false,
				data : {
					guid : $("#hid_serviceId").val(),
				},
				success : function(res) {
					$("#serverid").val(res.data.guid);
					$("#serverid").attr("disabled", true);
					$("#servicename").val(res.data.servicename);
					$("#templatecode").val(res.data.templatecode);
					$("input[name='radioshow'][value='"+res.data.showtype+"']").attr("checked",true);
					$("input[name='radioPagintion'][value='"+res.data.ispagination+"']").attr("checked",true);
					$("#reportdesc").val(res.data.reportdesc);
					$("#templateurl_span").html(res.data.templateUrl);
					$("#jrxmlurl_span").html(res.data.jrxmlUrl);
					//模板服务ID
					//$("#serviceid").val(res.data.guid);
				},
				error : function(res){
					bootbox.alert("获取模板配置信息异常!");
				}
			});
		},
		saveServerIdToSession: function() {
			$.ajax({
				type:'POST',
				url: postPath + '/system/reportconfig/saveServerId',
				async:false,
				data:{reportserverID:$("#serverid").val()},
				dataType : 'json',
                success:function(res){
	                 
                }
			});
		},
		//执行报表服务保存
		saveReportServerConfig:function() {
			var reportconfig ={
				guid:$("#serverid").val(),
				servicename:$("#servicename").val(),
				showtype:$("input[name='radioshow']:checked").val(),
				ispagination:$("input[name='radioPagintion']:checked").val(),
				reportdesc:$("#reportdesc").val(),
				pcode : $("#hid_projectid").val(),
			};
			var editurl = postPath + '/system/reportconfig/insertCfgExtreportToSession';
			var operate = $("#hid_operate").val();
			$.ajax({
				type:'POST',
				url: editurl,
				async:false,
				data:JSON.stringify(reportconfig),
				dataType : 'json',
                contentType:"application/json",
                success:function(res){
	                 if(res.success)
	               	 {	
	               		 //bootbox.alert("保存成功!");
	               		
	               	 }else{
	               		$("#valide_reportMessage").html("报表服务基本信息保存异常!");
	               		 //bootbox.alert("保存,请刷新后重试!");
	               	 }
                }
			});
			
		},
		validationReportConfig:function() {
			if ($("#serverid").val() == "") {
				$("#valide_reportMessage").html("服务ID不能为空!");
				return false;
			}else if(editReportStart == 1){
				var result=false;
				$.ajax({
		            type : 'POST',
		            url : postPath + '/system/reportconfig/valReportServerCode',
		            async : false,
		            data : {guid:$("#serverid").val()},
		            success : function(res) {
		            	if(res.success == false){
		        			$("#valide_reportMessage").html("报表服务ID已存在!");
		        			return false;
		        		}else{
		        			$("#valide_reportMessage").html("");
		        		}
		            }
		        });
				
			} else {
				$("#valide_reportMessage").html("");
			}
			if ($("#servicename").val() == "") {
				$("#valide_reportMessage").html("服务名称不能为空!");
				return false;
			} else {
				$("#valide_reportMessage").html("");
			}
			if ($("#templatecode").val() == "") {
				$("#valide_reportMessage").html("服务模板不能为空!");
				return false;
			} else {
				$("#valide_reportMessage").html("");
			}
			if ($("#reportdesc").val() == "") {
				$("#valide_reportMessage").html("服务说明不能为空!");
				return false;
			} else {
				$("#valide_reportMessage").html("");
			}
			return true;
		},
		valdationJrxmlJasper:function() {
			var val = false;
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/valJrxmlJasper',
				async : false,
				data : {guid:$("#serverid").val()},
				success : function(result){
					val = result;
				},
				error : function(error) {
					
				}
			});
			return val;
		},
};

//报表数据源配置属性配置模块
reportServer.dateSourcePropertyConfig={
		init:function() {
			
		},
		dateSourceConfigInit:function() {
			$.ajax({
				type : 'get',
				url : postPath + '/system/reportconfig/getReportDataSourceSize',
				async : false,
				data : {
					operate : $("#hid_operate").val(),
					serviceId : $("#serverid").val(),
				},
				success : function(res) {
					if(res.success){
						dataSource=res.data;
						var str =""
							str+="<div class=\"form-group tableleft\" style=\"width: 490px;\" >";
						    str+="<label class=\"col-md-4 control-label\" style=\"width: 122px;\">主数据源:</label>";
						    str+="<div class=\"col-md-4\" style=\"width: 350px;\">";
						    str+="<input type=\"file\" name=\"file\" id=\"defaultDateSource\" class=\"file-loading\" data-show-preview=\"false\"/>";
							str+="</div>";
							str+="</div>";
							str+="<div class=\"form-group\" style=\"\" >";
							str+="<div class=\"col-md-4\" style=\"width:430px;\">";
							str+="<span id=\"defaultDateSource_span\" style=\"color: green;\"></span>";
							str+="</div>";
							str+="</div>";
						for (var i = 0; i < res.data.length; i++) {
							str+="<hr>";
							str+="<div class=\"form-group tableleft\" style=\"width: 490px;\" >";
						    str+="<label class=\"col-md-4 control-label\" style=\"width: 122px;\">"+res.data[i].repdatasource+"数据源:</label>";
						    str+="<div class=\"col-md-4\" style=\"width: 350px;\">";
						    str+="<input type=\"file\" name=\"file\" id=\"dateSource_"+res.data[i].repdatasource+"\" class=\"file-loading\" data-show-preview=\"false\"/>";
							str+="</div>";
							str+="</div>";
							str+="<div class=\"form-group\" style=\"\" >";
							str+="<div class=\"col-md-4\" style=\"width:430px;\">";
							str+="<span id=\"dateSource_span_"+res.data[i].repdatasource+"\" style=\"color: green;\"></span>";
							str+="</div>";
							str+="</div>";
							str+="<hr>";
						}
					$("#dataSource_switch").html(str);
					}
				},
				error : function(res){
					bootbox.alert("获取数据源信息异常!");
				}
			});
			
		},
		dataSourceFileInputInit:function() {
			$('#defaultDateSource').fileinput({
		        language: 'zh', //设置语言
		        uploadUrl: postPath + 'system/reportconfig/uploadDataSourceFile', //上传的地址
	            maxFileCount : 1,
	            browseClass : "btn btn-info", //按钮样式 
		        uploadAsync: false, //默认异步上传
		        showUpload: true, //是否显示上传按钮
		        showRemove : true, //显示移除按钮
		        showPreview : false, //是否显示预览
		        allowedFileExtensions: ['xml'],
		        uploadExtraData: { 
		        	operate : $("#hid_operate").val(),
					serviceId : $("#serverid").val(),
		        	
		        }
		    }).on("filebatchuploadsuccess", function (event, data, previewId, index) {    //一个文件上传成功
		        //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
		    	if(data.response.success){
		    		bootbox.alert(data.response.msg);
		    		$("#defaultDateSource_span").html(data.files[0].name);
		    	}
		    });
			for (var i = 0; i < dataSource.length; i++) {
				$('#dateSource_'+dataSource[i].repdatasource).fileinput({
			        language: 'zh', //设置语言
			        uploadUrl:postPath + 'system/reportconfig/uploadDataSourceFile', //上传的地址
		            maxFileCount : 1,
		            browseClass : "btn btn-info", //按钮样式 
			        uploadAsync: false, //默认异步上传
			        showUpload: true, //是否显示上传按钮
			        showRemove : true, //显示移除按钮
			        showPreview : false, //是否显示预览
			        allowedFileExtensions: ['xml'],
			        uploadExtraData: { 
			        	operate : $("#hid_operate").val(),
						serviceId : $("#serverid").val(),
			        	
			        }

			    }).on("filebatchuploadsuccess", function (event, data, previewId, index) {    //一个文件上传成功
			        //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
			    	if(data.response){
			    		bootbox.alert('文件上传成功！');
			    		$("#dateSource_span_"+dataSource[i].repdatasource).html(data.files[0].name);
			    	}
			    });
			};
		},
		
		valDateSourceExist: function() {
			var bol = false;
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/valDateSourceExist',
				async : false,
				data : {
					operate : $("#hid_operate").val(),
					serviceId : $("#serverid").val(),
				},
				success : function(result){
					bol = result;
				},
				error : function(error) {
					
				}
			});
			return bol;
			
		}
};

reportServer.dataServerParmeterConfig={
		init:function() {
			
		},
		parmeterConfigInit:function() {
			$("#parmeter_config").bootstrapTable('destroy').bootstrapTable({
				url : postPath + '/system/reportconfig/getReportParmeters',
			    undefinedText : '-',
			    striped : true, // 是否显示行间隔色  
			    queryParams : {
			    	operate : $("#hid_operate").val(),
					serviceId : $("#serverid").val(),
			    }, 
			    uniqueId : "guid", // 每一行的唯一标识 
			    columns:[{
			    	field : 'state',  
			        checkbox : true,  
			        align : 'center',  
			        valign : 'middle'
			    },{
			    	title : '属性名称',  
			        field : 'parmetername',  
			        align : 'center', 
			        valign : 'middle'
			    },{
			    	title : '属性别名',  
			        field : 'aliasname',  
			        align : 'center', 
			        valign : 'middle'
			    },{
			    	title : '属性类型',  
			        field : 'datatype',  
			        align : 'center', 
			        valign : 'middle',
			    }/*,{
			    	title : '属性值',  
			        field : 'parmetervalue',  
			        align : 'center', 
			        valign : 'middle',
			        width : '200px',
			    }*/,{
			    	title : '默认值',
			        field : 'optionvalue',  
			        align : 'center', 
			        valign : 'middle',
			        width : '200px',
			    },{
			    	title : '是否输入',  
			        field : 'isterm',  
			        align : 'center', 
			        valign : 'middle',
			        width : '200px',
			        formatter:function(value,row,index){
				    	 var result="";
				    	 if(value==0){
				    		 result="是";
				    	 }else if(value == 1){
				    		 result = "否";
				    	 }
				    	 return result;
				     }
			    },{
			    	title : '属性说明',  
			        field : 'parmeterdesc',  
			        align : 'center', 
			        valign : 'middle'
			    }],
			    onCheck:reportServer.dataServerParmeterConfig.editParmeterConfig,
			    onUncheck:reportServer.dataServerParmeterConfig.saveParmeterConfig
			});
		},
		editParmeterConfig:function(row) {
			$("#parmeter_config").find("tr").each(function(){
	    		var trguid = $(this).attr("data-uniqueid");
	    		if(trguid == row.guid){
	    			var nRow = $(this);
			    	var jqTds = $('>td', nRow);
			    	jqTds[2].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.aliasname==null?"":row.aliasname) + '">';
//			    	jqTds[4].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.parmetervalue==null?"":row.parmetervalue) + '">';
			    	jqTds[4].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.optionvalue==null?"":row.optionvalue) + '">';
			    	jqTds[5].innerHTML = '<select class="form-control input-small" style="width:105px !important;">'
	    				+'<option '+(row.isterm==0?"selected='selected'":"")+' value="0">是</option>'
	    				+'<option '+(row.isterm==1?"selected='selected'":"")+' value="1">否</option>'
	    				+'</select>';
			    	jqTds[6].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.parmeterdesc==null?"":row.parmeterdesc) + '">';
	    		}
	    	});
		},
		saveParmeterConfig:function(row) {
			$("#parmeter_config").find("tr").each(function(){
	    		var trguid = $(this).attr("data-uniqueid");
	    		if(trguid == row.guid){
	    			var nRow = $(this);
			    	var jqTds = $('>td', nRow);
			    	var midffvalue = $(':input',nRow);
			    	var val = reportServer.dataServerParmeterConfig.valReportAliasnameExist(row.guid, midffvalue[1].value);
		            if(!val){
		            	bootbox.alert("参数别名已存在!");
		            	return false;
		            }
			    	var parmeter={
		            		guid:row.guid,
		            		aliasname:midffvalue[1].value,
//		            		parmetervalue:midffvalue[2].value,
		            		optionvalue:midffvalue[2].value,
		            		isterm:midffvalue[3].value,
		            		parmeterdesc:midffvalue[4].value,
		            };
		            $.ajax({
		                 type : 'POST',
		                 url : postPath + '/system/reportconfig/updateRepparmeterSession',
		                 async : false,
		                 data : JSON.stringify(parmeter),
		                 dataType : 'json',
		                 contentType:"application/json",
		                 success : function(data) {
		                	 $("#parmeter_config").bootstrapTable('refresh');
		                 }
		             });
	    		}
	    	});
		},
		valReportAliasnameExist: function(guid, aliasname) {
			var bol = true;
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/valReportAliasnameExist',
				async : false,
				data : {
					'guid' : guid,
					'aliasname' : aliasname,
				},
				success : function(result){
					bol = result;
				},
				error : function(error) {
					
				}
			});
			return bol;
		},
		dbParmeterShowTableConfig: function() {
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/getDateSourceServerConfig',
				async : false,
				data : {
					operate : $("#hid_operate").val(),
					serviceId : $("#serverid").val(),
				},
				success : function(result){
					var defaultstr = "";
					var sonstr = "";
					if(result != null) {
						for (var i = 0; i < result.length; i++) {
							if(result[i].repdatasource == "DefaultDataSource"){
								defaultstr+="<fieldset>";
								defaultstr+="<legend>默认数据服务参数配置</legend>";
								defaultstr+="<table id=\"dataServerParmeter_"+result[i].repdatasource+"\"></table>";
								defaultstr+="</fieldset>";
								defaultstr+="<br>";
							}else{
								sonstr+="<fieldset>";
								sonstr+="<legend>"+result[i].repdatasource+"数据服务参数配置</legend>";
								sonstr+="<table id=\"dataServerParmeter_"+result[i].repdatasource+"\"></table>";
								sonstr+="</fieldset>";
							}
						}
						$("#dataServerParmeter_table").html(defaultstr+sonstr+"<br><br>");
						for (var i = 0; i < result.length; i++) {
							$("#dataServerParmeter_"+result[i].repdatasource).bootstrapTable('destroy').bootstrapTable({
								url : postPath + '/system/reportconfig/getDataServerParmeters',
							    undefinedText : '-',
							    striped : true, // 是否显示行间隔色  
							    queryParams : {
							    	operate : $("#hid_operate").val(),
									serviceId : $("#serverid").val(),
									dataserviceid : result[i].dataserviceid,
							    }, 
							    uniqueId : "guid", // 每一行的唯一标识 
							    columns:[{
							    	field : 'state',  
							        checkbox : true,  
							        align : 'center',  
							        valign : 'middle'
							    },{
							    	title : '属性名称',  
							        field : 'parmetername',  
							        align : 'center', 
							        valign : 'middle'
							    },{
							    	title : '属性别名',  
							        field : 'aliasname',  
							        align : 'center', 
							        valign : 'middle'
							    },{
							    	title : '属性类型',  
							        field : 'datatype',  
							        align : 'center', 
							        valign : 'middle',
							    },/*{
							    	title : '属性值',  
							        field : 'parmetervalue',  
							        align : 'center', 
							        valign : 'middle',
							        width : '200px',
							    },*/{
							    	title : '属性值',  
							        field : 'optionvalue',  
							        align : 'center', 
							        valign : 'middle',
							        width : '200px',
							    },{
							    	title : '是否输入',  
							        field : 'isterm',  
							        align : 'center', 
							        valign : 'middle',
							        width : '200px',
							        formatter:function(value,row,index){
								    	 var result="";
								    	 if(value==0){
								    		 result="是";
								    	 }else if(value == 1){
								    		 result = "否";
								    	 }
								    	 return result;
								     }
							    },{
							    	title : '属性说明',  
							        field : 'parmeterdesc',  
							        align : 'center', 
							        valign : 'middle'
							    }],
							    onCheck:function (row) {
							    	var ds = reportServer.dataServerParmeterConfig.getDataSourceByServer(row.dataservercode);
							    	$("#dataServerParmeter_"+ds.repdatasource).find("tr").each(function(){
							    		var trguid = $(this).attr("data-uniqueid");
							    		if(trguid == row.guid){
							    			var nRow = $(this);
									    	var jqTds = $('>td', nRow);
									    	jqTds[2].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.aliasname==null?"":row.aliasname) + '">';
//									    	jqTds[4].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.parmetervalue==null?"":row.parmetervalue) + '">';
									    	jqTds[4].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.optionvalue==null?"":row.optionvalue) + '">';
									    	jqTds[5].innerHTML = '<select class="form-control input-small" style="width:105px !important;">'
							    				+'<option '+(row.isterm==0?"selected='selected'":"")+' value="0">是</option>'
							    				+'<option '+(row.isterm==1?"selected='selected'":"")+' value="1">否</option>'
							    				+'</select>';
									    	jqTds[6].innerHTML = '<input class="form-control input-small" style="width:105px !important;" type="text" value="' + (row.parmeterdesc==null?"":row.parmeterdesc) + '">';
							    		}
							    	});
							    },
							    onUncheck:function (row) {
							    	var ds = reportServer.dataServerParmeterConfig.getDataSourceByServer(row.dataservercode);
							    	$("#dataServerParmeter_"+ds.repdatasource).find("tr").each(function(){
							    		var trguid = $(this).attr("data-uniqueid");
							    		if(trguid == row.guid){
							    			var nRow = $(this);
									    	var jqTds = $('>td', nRow);
									    	var midffvalue = $(':input',nRow);
									    	var val = reportServer.dataServerParmeterConfig.valDBAliasnameExist(row.guid, midffvalue[1].value);
								            if(!val){
								            	bootbox.alert("参数别名已存在!");
								            	return false;
								            }
								            var parmeter={
								            		guid:row.guid,
								            		aliasname:midffvalue[1].value,
//								            		parmetervalue:midffvalue[2].value,
								            		optionvalue:midffvalue[2].value,
								            		isterm:midffvalue[3].value,
								            		parmeterdesc:midffvalue[4].value,
								            };
								            $.ajax({
								                 type : 'POST',
								                 url : postPath + '/system/reportconfig/updateDataServerParmeters',
								                 async : false,
								                 data : JSON.stringify(parmeter),
								                 dataType : 'json',
								                 contentType:"application/json",
								                 success : function(data) {
								                	 $("#dataServerParmeter_"+ds.repdatasource).bootstrapTable('refresh');
								                 }
								             });
							    		}
							    	});
							    },
							});
						}
					}
				},
				error : function(error) {
					
				}
			});
		},
		getDataSourceByServer:function(serverId) {
			var data;
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/getDataSourceByServer',
				async : false,
				data : {
					'serverId' : serverId,
				},
				success : function(result){
					data = result;
				},
				error : function(error) {
					
				}
			});
			return data;
		},
		dbParmeterConfigInit:function(repsource) {
			
		},
		editDbParmeterConfig:function(row,repsource) {
			
		},
		saveDbParmeterConfig:function(row,repsource) {
			
		},
		valDBAliasnameExist: function(guid, aliasname) {
			var bol = true;
			$.ajax({
				type : 'post',
				url : postPath + '/system/reportconfig/valDBAliasnameExist',
				async : false,
				data : {
					'guid' : guid,
					'aliasname' : aliasname,
				},
				success : function(result){
					bol = result;
				},
				error : function(error) {
					
				}
			});
			return bol;
		},
};












//var abc=(function(y){  
//var x=y;// 这个是局部变量  
//return function(){  
//  alert(x++);// 就是这里调用了闭包特性中的一级函数局部变量的x，并对它进行操作  
//  alert(y--);// 引用的参数变量也是自由变量  
//}})(10);// 初始化  
	
	
//$(document).ready(function(){
//	
////	abc(10);
////	abc();
////	abc();
//	//参数
